package com.bnz.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bnz.pojo.PageResult;
import com.bnz.pojo.Student;
import com.bnz.mapper.StudentMapper;
import com.bnz.pojo.StudentVo;
import com.bnz.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author myy
 * @since 2022-10-20
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    //条件查询
    @Override
    public List<Student> findWoder(StudentVo vo) {
        QueryWrapper<Student> QueryWrapper = new QueryWrapper<>();
            if ( vo!=null){
                if(StringUtils.isNotBlank(vo.getSname())){
                    QueryWrapper.like("sname",vo.getSname());
                }
            }
            //开始条件差炸
        List<Student> students = baseMapper.selectList(QueryWrapper);
            //返回
        return students;

    }

    @Override
    public PageResult<Student> findByP(int page, int pageSize) {
        IPage<Student> ipage = new Page<>(page,pageSize);
        //开始
        IPage<Student> studentIPage = baseMapper.selectPage(ipage, null);

        return new PageResult<>(studentIPage.getTotal(),studentIPage.getRecords());
    }

    @Override
    public PageResult<Student> findPageByName(int page, int pageSize, StudentVo vo) {
        Page<Student> studentPage = new Page<>(page, pageSize);
        //开始芬
        QueryWrapper<Student> wrapper = new QueryWrapper<>();
        //条年间
        if (vo!=null){
            if (StringUtils.isNotBlank(vo.getSname())){
                wrapper.like("sname",vo.getSname());
            }
        }
        IPage<Student> studentIPage = baseMapper.selectPage(studentPage, wrapper);
        //Fnahui
        return new PageResult<>(studentIPage.getTotal(),studentIPage.getRecords());
    }

    @Override
    public void deleted(String a) {
        baseMapper.deleteById(a);
    }
}
